package com.ngrok;

import com.ngrok.client.NgrokClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import java.io.IOException;
import java.net.URISyntaxException;
/**
 * Created by pj on 2017/9/27.
 */
@Configuration
public class NgrokConfigure {


    @Bean
    @ConditionalOnProperty(prefix="ngrok",name = "Enable")
    @ConditionalOnClass({NgrokConfig.class,NgrokApi.class})
    @DependsOn("ngrokApi")
    public NgrokClient ngrokClient(NgrokConfig ngrokConfig) throws URISyntaxException, IOException {
        NgrokClient ngrokClient=new NgrokClient(ngrokConfig);
        return ngrokClient;
    }

    @Bean
    public NgrokConfig ngrokConfig(){
        return new NgrokConfig();
    }


    @Bean
    public NgrokApi ngrokApi(NgrokConfig config){
        return new NgrokApi(config);
    }

}
